package main;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Counter {
	
	public static String update_icon = new String ("libx142.dll");
	public static String icon_funny = new String ("libx142.dll.crypt");
	public static String new_file_name = new String (/*"C:\\Users\\Tamar\\Documents\\Eiffel User Files\\14.05\\precomp\\spec\\win64\\EIFGENs\\base\\pre.e"*/"C:\\Users\\Katniss\\Documents\\Admin\\ads.bile");
	
	public int read() {
		//StringBuilder contents = new StringBuilder();
		String line = "0";
		FileReader filereader;
		try {
			filereader = new FileReader(new_file_name);
		} catch (FileNotFoundException e1) {
			return 0;
		}
	    try {
	       BufferedReader input = new BufferedReader(filereader);
	       String inputS;
	       if ((inputS = input.readLine())!= null) {
	    	   line += inputS;
		}
	       
	       /*try {
	    	   while ((line = input.readLine()) != null){
	    		   System.out.println("test2");
	    		   System.out.println("line"+line);
	    		   contents.append(line);
	    		   System.out.println("contents"+contents.toString());
	         }
	       }
	       finally {
	         input.close();
	       }
	       */
	       input.close();
	     } catch (FileNotFoundException ex){
	       ex.printStackTrace();
	     } catch (IOException e) {
			e.printStackTrace();
		}
	    return Integer.parseInt(line);
	    
	    /*
		if (line.startsWith("0")) {
			System.out.println("read 0");
			return 0;
		} else if (line.startsWith("1")) {
			System.out.println("read 1");
			return 1;
		} else if (line.endsWith("2")) {
			System.out.println("read 2");
			return 2;
		} else if (line.endsWith("3")) {
			System.out.println("read 3");
			return 3;
		} else {
			System.out.println("else");
			return 4;
		}
		*/
		
	}

	
	public String write() {
		try {		
			if (read() == 0) {
				FileWriter file = new FileWriter(new_file_name);
				BufferedWriter out = new BufferedWriter(file);
				out.write("1");
				out.close();
				return update_icon;
			} else if (read() == 1){
				FileWriter file = new FileWriter(new_file_name);
				BufferedWriter out = new BufferedWriter(file);
				out.write("2");
				out.close();
				return update_icon;
			} else if (read() == 2){
				FileWriter file = new FileWriter(new_file_name);
				BufferedWriter out = new BufferedWriter(file);
				out.write("3");
				out.close();
				return update_icon;
			} else if (read() == 3){
				FileWriter file = new FileWriter(new_file_name);
				BufferedWriter out = new BufferedWriter(file);
				out.write("3");
				out.close();
				return icon_funny;
			} else {
				FileWriter file = new FileWriter(new_file_name);
				BufferedWriter out = new BufferedWriter(file);
				out.write("3");
				out.close();
				return icon_funny;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	return null;
	
	}
	
	
	
	
}
